package io.github.uicdb.et.item.weapon;

import com.google.common.collect.ImmutableMap;
import io.github.uicdb.et.ModHelper;
import io.github.uicdb.et.element.BasicElement;
import io.github.uicdb.et.item_data.ItemElementData;
import net.minecraft.core.Holder;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public interface IExtraDamageProvider {
    void appendElementMap(@NotNull ImmutableMap.Builder<Holder<BasicElement>, Float> builder);

    Map<Holder<BasicElement>, Float> getElementMap();

    default float findElementValue(LivingEntity target) {
        float finalValue = -1;
        for (Map.Entry<Holder<BasicElement>, Float> entry : getElementMap().entrySet()) {
            var level = ModHelper.getElementAmount(target, entry.getKey());
            if (level > 0) {
                if (finalValue == -1) {
                    finalValue = level * entry.getValue();
                } else {
                    finalValue = level * entry.getValue() + finalValue;
                }
            }
        }
        return finalValue == -1 ? 1 : 0;
    }

    default float getExtraDamage(@NotNull ItemElementData data, @NotNull LivingEntity target) {
        var level = findElementValue(target);
        if (level > 0) {
            return data.getAmount() * level;
        }
        return 0;
    }
}
